package wei.xinya.core.arrays;

import java.util.ArrayList;

import static java.util.Collections.*;

public class ArraysOperator {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(-1);
        arrayList.add(2);
        arrayList.add(2);
        arrayList.add(-5);
        arrayList.add(7);
        arrayList.add(4);
        arrayList.add(-9);
        arrayList.add(-7);
        ArrayList<Integer> arrayList2 = new ArrayList<>();
        arrayList2.add(-3);
        arrayList2.add(-5);
        arrayList2.add(7);
        System.out.println("原始数组:");
        System.out.println(arrayList);

        System.out.println("Collections.max(arrayList):");
        System.out.println(max(arrayList));

        System.out.println("Collections.min(arrayList):");
        System.out.println(min(arrayList));

        System.out.println("Collections.replaceAll(arrayList, 2, -3):");
        boolean b = replaceAll(arrayList, 2, -3);
        if (b) System.out.println(arrayList);

        System.out.println("Collections.frequency(arrayList, -3):");
        System.out.println(frequency(arrayList, -3));

        System.out.println("Collections.indexOfSubList(arrayList, arrayList2):");
        System.out.println(indexOfSubList(arrayList, arrayList2));

        System.out.println("Collections.binarySearch(arrayList, 7):");

        // 对List进行二分查找，返回索引，List必须是有序的
        sort(arrayList);
        System.out.println(arrayList);
        System.out.println(binarySearch(arrayList, -5));
    }
}
